//
//  AccountOrderListCell.m
//  ImGuider
//
//  Created by llt on 2017/6/10.
//  Copyright © 2017年 imguider. All rights reserved.
//

#import "AccountOrderListCell.h"
#import "StarRateView.h"

@interface AccountOrderListCell ()
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *orderNOLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *payResultLabel;
@property (weak, nonatomic) IBOutlet UILabel *moneyLabel;
@property (weak, nonatomic) IBOutlet StarRateView *rateView;

@end

@implementation AccountOrderListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.contactServiceBtn.layer.cornerRadius = 2.0f;
    self.contactServiceBtn.layer.borderWidth = 1.0f;
    self.contactServiceBtn.layer.borderColor = kThemeColor.CGColor;
    [self.contactServiceBtn setTitle:MYLocalizedString(@"MYORDER_CONTACTSTAFF", nil) forState:UIControlStateNormal];
    
    self.evaluateBtn.layer.cornerRadius = 2.0f;
    self.evaluateBtn.layer.borderWidth = 1.0f;
    self.evaluateBtn.layer.borderColor = kThemeColor.CGColor;

    [self.evaluateBtn setTitle:MYLocalizedString(@"PUBLIC_COMMENT_TITLE", nil) forState:UIControlStateNormal];
    
    [self.orderNOLabel addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(copyOrderID)]];
    self.orderNOLabel.userInteractionEnabled = YES;
}

- (void)copyOrderID {
    
    NSString *contact = self.orderNOLabel.text;
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = contact;
    
    [IGUtil showToast:MYLocalizedString(@"CONTACT_COPY_SUCCESS", nil)];
}

- (void)setOrder:(OrderModel *)order {
    
    _order = order;
    self.titleLabel.text = order.subject;
    self.orderNOLabel.text = [NSString stringWithFormat:@"%@：%@",MYLocalizedString(@"MYORDER_ORDERNO", nil),order.ordernumber];
    self.timeLabel.text = [[NSDate dateWithTimeIntervalSince1970:order.ordertime.doubleValue / 1000] stringWithFormat:@"yyyy-MM-dd HH:mm"];
    NSString *result = [NSString stringWithFormat:@"%@",order.orderstatus.integerValue == 1 ? MYLocalizedString(@"MYORDER_SUCCESS", nil):MYLocalizedString(@"MYORDER_FAILED", nil)];
    
//    支付方式:0免费，1PAYPAL，2支付宝，3微信，4苹果内购，5谷歌，6携程订单，7虚拟币
    
    NSString *paytype = @"";
    switch (order.paytype.integerValue) {
        case 1:
            paytype = @"Paypal";
            break;
        case 2:
            paytype = MYLocalizedString(@"PAYORDER_TYPE_ALIPAY", nil);
            break;
        case 3:
            paytype = MYLocalizedString(@"PAYORDER_TYPE_WX", nil);
            break;
        case 4:
            paytype = MYLocalizedString(@"PAYORDER_TYPE_IAP", nil);
            break;
        case 5:
            paytype = @"Google Wallet";
            break;
        case 7:
            paytype = MYLocalizedString(@"PAYORDER_TYPE_COIN", nil);
            break;
            
        default:
            break;
    }
    
    if (paytype.length > 0) {
        self.payResultLabel.text = [NSString stringWithFormat:@"%@——%@",result,paytype];
    } else {
        
        self.payResultLabel.text = result;
    }
    
    
    if (order.paytype.integerValue == 7) {
        self.moneyLabel.text = [NSString stringWithFormat:@"%@ %@",@(order.amount.floatValue / 100),MYLocalizedString(@"PUBLIC_COIN_NAME", nil)];
    } else {
        self.moneyLabel.text = order.realpay;
    }
    
    if (order.score) {
        
        self.rateView.hidden = NO;
        self.evaluateBtn.hidden = YES;
        
        [self.rateView setScore:order.score.floatValue / 10];
    } else {
        
        self.rateView.hidden = YES;
        self.evaluateBtn.hidden = NO;
    }
}

@end
